package com.juzipi.demo.controller;

import com.juzipi.demo.model.PageBody;
import com.juzipi.demo.pojo.Student;
import com.juzipi.demo.service.StudentPlusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author juzipi
 * @Date 2021/5/3 15:26
 * @Info
 */
@RestController
@RequestMapping("plus")
public class StudentPlusController {

    @Autowired
    private StudentPlusService studentPlusService;


    @GetMapping("{id}")
    public Student get(@PathVariable Long id){
        Student student = studentPlusService.queryById(id);
        return student;
    }

    @GetMapping("list")
    public List<Student> list(){
        return studentPlusService.queryList();
    }

    @PostMapping("condition/one")
    public List<Student> condition(@RequestBody Student student){
        return studentPlusService.queryListByName(student);
    }

    @PostMapping("condition/two")
    public Student conditions(@RequestParam String name){
        return studentPlusService.queryByName(name);
    }


    /**
     * 模糊查询返回分页
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping("page")
    public Map<String, Object> page(@RequestParam String key,
                                    @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize",defaultValue = "2") Integer pageSize
                                    ){
        return studentPlusService.queryPageByLike(key, pageNum, pageSize);
    }


    @PostMapping("insert")
    public Boolean insert(@RequestBody Student student){
        return studentPlusService.insert(student);
    }


    @PutMapping("update")
    public Boolean update(@RequestBody Student student){
        return studentPlusService.update(student);
    }

    @DeleteMapping("del/{id}")
    public Boolean delete(@PathVariable String id){
        return studentPlusService.delete(id);
    }


    @GetMapping("getList/{age}")
    public List<Student> getListByAge(@PathVariable Integer age){
        return studentPlusService.queryListByAge(age);
    }

    @PostMapping("page")
    public Map<String, Object> getPage(@RequestBody PageBody pageBody){
        studentPlusService.queryPageLikePlus(pageBody);
    }

}
